package com.example.Arithmetic.Lettcode;

/**
 * 日期：2023/12/28
 * 时间：11:48
 * 描述：力扣1122题
 * 计数排序，先给指定数组内的排序，然后再次给不在数组中的元素排序
 */
public class E01Lettcode1122 {
    public int[] relativeSortArray(int[] arr1, int[] arr2) {
        int[] array = new int[1001];
        for (int a1 : arr1) {
            array[a1]++;
        }
        int k = 0;
        for (int a2 : arr2) {
            while (array[a2] > 0) {
                arr1[k++] = a2;
                array[a2]--;
            }
        }
        for (int i = 0; i < array.length; i++) {
            while (array[i] > 0) {
                arr1[k++] = i;
                array[i]--;
            }
        }
        return arr1;
    }

    public static void main(String[] args) {
        int[] arr1 = new int[]{2, 3, 1, 3, 2, 4, 6, 7, 9, 2, 19};
        int[] arr2 = new int[]{2, 1, 4, 3, 9, 6};
        E01Lettcode1122 e01Lettcode1122 = new E01Lettcode1122();
        e01Lettcode1122.relativeSortArray(arr1, arr2);
    }
}

